package com.aier.user.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.classes.entity.Classes;
import com.aier.common.common.CommonSession;
import com.aier.common.common.SystemConfigStatic;
import com.aier.school.entity.School;
import com.aier.user.entity.User;
import com.aier.user.service.IUserMessageService;
import com.aier.user.service.IUserService;

@Scope("prototype")
@Component("userHomeCommonAction")
public class UserHomeCommonAction extends UserBaseAction {

    /**
     * 首页顶栏与左栏、右栏
     */
    private static final long serialVersionUID = 1L;
    
    @Resource(name = "userService")
    private IUserService userService;
    @Resource(name="userMessageService")
    private IUserMessageService userMessageService;
    
    private int s;

    private List<School> schoolList; // 用户所在学校
    private List<Classes> classList; // 用户所在班级
    
    private Long uid;
    private Long tid;
    private Long cid;
    private Integer sid;
    
    private List<String> strList;
    
    
    private String imgUrl = SystemConfigStatic.get_picturl_url;
    
    private String headimg;
    
    // 最新消息类型（1查看粉丝2查看@我3查看通知）
    private Short type;

    @SuppressWarnings("unchecked")
    @Override
    public String execute() {
        schoolList = (List<School>) request.getSession().getAttribute(
                CommonSession.SESSION_ACCOUNT_SCHOOLLIST);
        classList = (List<Classes>) request.getSession().getAttribute(
                CommonSession.SESSION_ACCOUNT_CLASSLIST);
        uid = (Long) session.get(CommonSession.SESSION_ACCOUNT_ID);
        User u = userService.getUserByUid((Long) session.get(CommonSession.SESSION_ACCOUNT_ID));
        if (null != u) {
            headimg = u.getHeadimg();
        }
        return SUCCESS;
    }
    
    /**
     * 查询最新消息(开始时插入默认信息)
     * @return
     */
    public String searchLatestNotice() {
        strList = userMessageService.insertOrSearchLatestNotice((Long) request.getSession().getAttribute(CommonSession.SESSION_ACCOUNT_ID));
        s = 1;
        return SUCCESS;
    }
    
    /**
     * 新增或修改用户最新动作的记录
     * @return
     */
    public String insertAction() {
        s = userMessageService.insertAction((Long) request.getSession().getAttribute(CommonSession.SESSION_ACCOUNT_ID), type);
        return SUCCESS;
    }

    public List<School> getSchoolList() {
        return schoolList;
    }

    public List<Classes> getClassList() {
        return classList;
    }

    public Long getUid() {
        return uid;
    }

    public void setUid(Long uid) {
        this.uid = uid;
    }

    public Long getTid() {
        return tid;
    }

    public void setTid(Long tid) {
        this.tid = tid;
    }

    public Long getCid() {
        return cid;
    }

    public void setCid(Long cid) {
        this.cid = cid;
    }

    public Integer getSid() {
        return sid;
    }

    public void setSid(Integer sid) {
        this.sid = sid;
    }

    public void setUserService(IUserService userService) {
        this.userService = userService;
    }

    public String getImgUrl() {
        return imgUrl;
    }

    public String getHeadimg() {
        return headimg;
    }

    public void setUserMessageService(IUserMessageService userMessageService) {
        this.userMessageService = userMessageService;
    }

    public int getS() {
        return s;
    }

    public List<String> getStrList() {
        return strList;
    }

    public void setType(Short type) {
        this.type = type;
    }

}
